class HomeController < ApplicationController

    skip_filter :is_logged

    def index
        @usuario = Usuario.new
        unless session['usuario'].nil?
            @alunos = Aluno.count
            @voluntarios = Voluntario.count
            @aulas = Aula.count
            @escolas = Escola.count
        end
    end

    def login
        @usuario = Usuario.find(:first, :conditions => {:email => params[:email], :password => params[:senha]})
        if @usuario.nil?
            session["usuario"] = nil
            session["nivel"] = nil
        else
            session["usuario"] = @usuario
            voluntario = Voluntario.find(:first, :conditions => {:usuario_id => @usuario.id})
            if voluntario.nil?
                session["nivel"] = 1 # admin
            else
                session["nivel"] = 2 # voluntario
            end
        end


       redirect_to :action => "index"       

    end

    def logout
        session["usuario"] = nil
        session["nivel"] = nil
        redirect_to :action => "index"
    end

end
